package com.lh0811.forge.pserv.uacs.server.adapter.controller;

import com.github.pagehelper.PageInfo;
import com.lh0811.forge.dependency.basic_web.constant.AuthConstant;
import com.lh0811.forge.dependency.basic_web.response.ServerResponse;
import com.lh0811.forge.dependency.security.client.component.annotation.HasUrl;
import com.lh0811.forge.pserv.uacs.api.param.*;
import com.lh0811.forge.pserv.uacs.api.vo.TDesignCascaderVo;
import com.lh0811.forge.pserv.uacs.api.vo.UacsPlateResQueryVo;
import com.lh0811.forge.pserv.uacs.api.vo.UacsPlateResTreeVo;
import com.lh0811.forge.pserv.uacs.server.service.PlateResService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Tag(name = "权限中心-平台资源管理")
@RestController
@RequestMapping("/forge/plate/v1/uacs/plate_res")
public class OpmsPlateResController {

    @Resource
    private PlateResService plateResService;


    // 创建资源
    @HasUrl
    @PutMapping("/create")
    @Operation(summary = "创建资源", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse plateResCreate(@RequestBody @Valid UacsPlateResCreateParam param) throws Exception {
        plateResService.plateResCreate(param);
        return ServerResponse.createBySuccess();
    }

    // 删除资源
    @HasUrl
    @DeleteMapping("/delete/{resId}")
    @Operation(summary = "删除资源", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse plateResDelete(@PathVariable(value = "resId") Long resId) throws Exception {
        plateResService.plateResDelete(resId);
        return ServerResponse.createBySuccess();
    }

    // 资源更新
    @HasUrl
    @PostMapping("/update")
    @Operation(summary = "资源更新", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse plateResUpdate(@RequestBody @Valid UacsPlateResUpdateParam param) throws Exception {
        plateResService.plateResUpdate(param);
        return ServerResponse.createBySuccess();
    }

    // 资源查询(分页)
    @HasUrl
    @GetMapping("/query/page")
    @Operation(summary = "资源查询（分页）", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<PageInfo<UacsPlateResQueryVo>> plateResQueryPage(@ParameterObject @Valid UacsPlateResQueryPageParam param) throws Exception {
        return ServerResponse.createBySuccess("查询成功", plateResService.plateResQueryPage(param));
    }

    // 资源查询(不分页)
    @HasUrl
    @GetMapping("/query/list")
    @Operation(summary = "资源查询（不分页）", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<List<UacsPlateResQueryVo>> plateResQueryList(@ParameterObject @Valid UacsPlateResQueryListParam param) throws Exception {
        return ServerResponse.createBySuccess("查询成功", plateResService.plateResQueryList(param));
    }

    // 资源查询(树结构)
    @HasUrl
    @GetMapping("/query/tree")
    @Operation(summary = "资源查询（树结构）", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<List<UacsPlateResTreeVo>> plateResQueryTree(@ParameterObject @Valid UacsPlateResQueryTreeParam param) throws Exception {
        return ServerResponse.createBySuccess("查询成功", plateResService.plateResQueryTree(param));
    }


    // 资源查询(级联结构)
    @HasUrl
    @GetMapping("/query/cascader")
    @Operation(summary = "资源查询(级联结构)", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<List<TDesignCascaderVo>> plateResQueryTreeCascader() throws Exception {
        return ServerResponse.createBySuccess("查询成功", plateResService.plateResQueryTreeCascader());
    }

}
